
import os  


# #计算一个类别的mAP
# from voc_eval import voc_eval
# os.chdir("./mAP")
# print(os.getcwd())

# rec,prec,ap = voc_eval("./calc_mAP/print_detector_detections/{}.txt","./calc_mAP/xml/{}.xml","./calc_mAP/test_files.txt","backpack",'./pkl')

# print("rec:",rec)
# print("prec:",prec)
# print("ap:",ap)


# #计算全部类别的AP 进行平均求得 mAP
from voc_eval_all import voc_eval
print(os.getcwd())

cnt_ap = 0
total_ap = 0
total_prec = 0
total_rec = 0
for i in os.listdir("./print_detector_detections"):
    className = i[:i.find(".")]
    rec,prec,ap = voc_eval("./print_detector_detections/{}.txt","./Annotations/{}.xml","./JPEGImages_set.txt",className,'./pkl')
    if(ap == 0):
        continue
    cnt_ap += 1
    total_ap += ap
    total_prec += prec
    total_rec += rec 
    print(className,"\'s ap:%.4f, rec:%.4f, prec:%.4f"%(ap, rec, prec))
print(cnt_ap,"class' mAP:%.4f, rec:%.4f, prec:%.4f"%(total_ap/cnt_ap, total_rec/cnt_ap, total_prec/cnt_ap))